import Vue from 'vue'
import VueRouter from 'vue-router'

// import Login from '../components/Login.vue'
// import Home from '../components/Home.vue'
// import Welcome from '../components/home/Welcome.vue'

// import Users from '../components/home/users/Users.vue'
// import Rights from '../components/home/rights/Rights.vue'
// import Roles from '../components/home/rights/Roles.vue'

// import Cate from '../components/home/goods/Cate.vue'
// import Params from '../components/home/goods/Params.vue'
// import List from '../components/home/goods/List.vue'


// import Add from '../components/home/goods/Add.vue'
// import Order from '../components/home/order/Order.vue'
// import Report from '../components/home/report/Report.vue'
// 路由懒加载
const Login = () => import(/* webpackChunkName: 'login-home-welcome' */ '../components/Login.vue') 
const Home = () => import(/* webpackChunkName: 'login-home-welcome' */ '../components/Home.vue') 
const Welcome = () => import(/* webpackChunkName: 'login-home-welcome' */ '../components/home/Welcome.vue') 


const Users = () => import(/* webpackChunkName: 'Users-Rights-Roles' */ '../components/home/users/Users.vue') 
const Rights = () => import(/* webpackChunkName: 'Users-Rights-Roles' */ '../components/home/rights/Rights.vue') 
const Roles = () => import(/* webpackChunkName: 'Users-Rights-Roles' */ '../components/home/rights/Roles.vue') 

const Cate = () => import(/* webpackChunkName: 'Cate-Params-List' */ '../components/home/goods/Cate.vue') 
const Params = () => import(/* webpackChunkName: 'Cate-Params-List' */ '../components/home/goods/Params.vue') 
const List = () => import(/* webpackChunkName: 'Cate-Params-List' */ '../components/home/goods/List.vue') 


const Add = () => import(/* webpackChunkName: 'Add-Order-Report' */ '../components/home/goods/Add.vue') 
const Order = () => import(/* webpackChunkName: 'Add-Order-Report' */ '../components/home/order/Order.vue') 
const Report = () => import(/* webpackChunkName: 'Add-Order-Report' */ '../components/home/report/Report.vue') 


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login,
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      {path: '/welcome', component: Welcome},
      {path: '/users', component: Users,},
      {path: '/rights', component: Rights},
      {path: '/roles', component: Roles},
      {path: '/categories', component: Cate},
      {path: '/params', component: Params},
      {path: '/goods', component: List},
      {path: '/goods/add', component: Add},
      {path: '/orders', component: Order},
      {path: '/reports', component: Report}

    ]
  },
  
]

const router = new VueRouter({
  routes,
  mode: 'history'

})

router.beforeEach((to, from, next) => {
  if(to.path == '/login') return next();

  const token = window.sessionStorage.getItem('token');
  if(!token) {
    // this.$message.error("请先登录!")
    return next('/login')
  }

  next();

})

export default router
